package com.dududu.xiaoxueqi;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "http://localhost:5500") // 替换为你前端运行的地址
public class SearchController {

    @Autowired
    private SearchContentRepository searchContentRepository;

    @GetMapping("/search")
    public ResponseEntity<List<SearchContent>> search(@RequestParam String q) {
        List<SearchContent> results = searchContentRepository.findByTitleContainingOrDescriptionContaining(q, q);
        return ResponseEntity.ok(results);
    }
}
